home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 82 / tinytool.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  28KB  |  872 lines

  1.                                                 /* Alain Birtz, 16/2/86 */
  2. #include "gemdefs.h"
  3.  
  4. /************************************************************************/
  5.  
  6. #define NO_WINDOW       (-1)
  7. #define WI_KIND         (MOVER|CLOSER|NAME)     /* can be moved, closed */
  8.                                                 /* and title exist      */
  9.  
  10. #define Cprnout(a)      gemdos(0x5,a)
  11. #define Dsetdrv(a)      gemdos(14,a)
  12. #define Cprnos()        gemdos(0x11)
  13. #define Fopen(a,b)      gemdos(0x3d,a,b)
  14. #define Fclose(a)       gemdos(0x3e,a)
  15. #define Fread(a,b,c)    gemdos(0x3f,a,b,c)
  16. #define Fwrite(a,b,c)   gemdos(0x40,a,b,c)
  17. #define Fseek(a,b,c)    gemdos(0x42,a,b,c)
  18.  
  19. #define Getrez()                        (int)xbios(4)
  20. #define Floprd(a,b,c,d,e,f,g)           xbios(8,a,b,c,d,e,f,g)
  21. #define Flopwr(a,b,c,d,e,f,g)           xbios(9,a,b,c,d,e,f,g)
  22. #define Supexec(a)                      xbios(38,a)
  23.  
  24. #define digitoi(n)      ( n - ((n<'A') ? '0' : ((n<'a') ? 55 : 87)) )
  25.  
  26. /************************************************************************/
  27.  
  28. extern long     gemdos();
  29. extern long     xbios();
  30. extern int      gl_apid;
  31.  
  32. /************************************************************************/
  33.  
  34. int     menu_id ;                       /* our menu id                  */
  35. int     handle;                         /* virtual workstation          */
  36. int     phys_handle;                    /* physical workstation         */
  37. int     wi_handle;                      /* window handle                */
  38. int     top_window;                     /* handle of topped             */
  39. int     xdesk,ydesk,hdesk,wdesk;
  40. int     xwork,ywork,hwork,wwork;        /* desktop , work areas         */
  41. int     msgbuff[8];                     /* event message buffer         */
  42. int     mx,my;                          /* mouse x and y position       */
  43. int     butdown;                        /* button state                 */
  44. int     d;                              /* dummy variable               */
  45.  
  46. int     contrl[12];                     /* AES, VDI variable            */
  47. int     intin[128];
  48. int     ptsin[128];
  49. int     intout[128];
  50. int     ptsout[128];
  51. int     work_in[11];                    /* Input GSX parameter          */
  52. int     work_out[57];                   /* Output GSX parameter         */
  53.  
  54. int mode;                               /* read=0, write=1              */
  55. int drv,side,sec,trk,buf512[512];       /* used in sector editor        */
  56. int open_flag;                          /* set to 1 if file is open     */
  57. int exit;                               /* exit flag                    */
  58. int clear_flag;                         /* if 1, erase last message     */
  59. int ed_choice;                          /* user choice editor           */
  60. int h_chr;                              /* character height             */
  61. int dev=2;                              /* device: screen=2, printer=0  */
  62. int intro_lvl;                          /* flag in draw(),clicked()     */
  63. int wd[4],ed_scr[4],mess[4];            /* rectangular area             */
  64. int ch[3][4],box[5][4];                 /* clickable button             */
  65. char line_str[49];                      /* dilplaying line              */
  66. char buf64[64];                         /* current byte displaying      */
  67. char *main_ptr,*temp_ptr;               /* work pointer                 */
  68. long counter;                           /* first value displaying       */
  69. long file_handle;                       /* allocated file number        */
  70.  
  71. /************************************************************************/
  72.  
  73. ltohxs(lg,s,len)                /* convert in hexadecimal the value of  */
  74. char s[];                       /* lg to a char string s of length      */
  75. long lg;                        /* 'len' with leading zero              */
  76. int len;
  77. {
  78. int i, n;
  79. long t_lg;
  80.  
  81.         s[len]='\0';
  82.         i=len-1;
  83.  
  84.         {
  85.         while (i>-1)
  86.                 {
  87.                 t_lg=lg;
  88.                 n=(int) (t_lg & 0xFL);
  89.                 s[i--]=n+48+(n>9)*7;
  90.                 lg >>= 4;
  91.                 }
  92.         }
  93. }
  94.  
  95. /************************************************************************/
  96.  
  97. long stol(s,b)                  /* s is a (string) number in base b     */
  98. char *s;                        /* return this number (long integer)    */
  99. int b;
  100. {
  101. long lg;
  102. char cc;
  103.  
  104.         lg=0L;
  105.         while((cc = *s++))
  106.                 lg=lg*b+digitoi(cc);
  107.         return(lg);
  108. }
  109.  
  110. /************************************************************************/
  111.  
  112. long l_param(x)                 /* return a long parameter given        */
  113. int x;                          /* by the user, echo at x char from     */
  114. {                               /* start of message screen              */
  115. int base;
  116. char s[11], *t;
  117.  
  118.         graf_mouse(256,0);              /* hide mouse                   */
  119.         readline(s,10,mess[0]+12+x*8,mess[1]+h_chr);
  120.         graf_mouse(257,0);              /* show mouse                   */
  121.  
  122.         if (s[0]=='$')
  123.                 {
  124.                 base=16;
  125.                 t=s+1;
  126.                 }
  127.         else
  128.                 {
  129.                 base=10;
  130.                 t=s;
  131.                 }
  132.  
  133.         return(stol(t,base));
  134. }
  135.  
  136. /************************************************************************/
  137.  
  138. i_param(x)                      /* return a integer parameter given     */
  139. int x;                          /* by the user, echo at x char from     */
  140. {                               /* start of message screen              */
  141. int n;
  142.  
  143.         n=(int) l_param(x);
  144.         return(n);
  145. }
  146.  
  147. /************************************************************************/
  148.  
  149. file_sel()                      /* set file_handle > -1 if succesfully  */
  150. {                               /* openned, -1 if an error occur        */
  151. static char pathname[51]="A:\\*.*";
  152. char filename[13],*ptr1,*ptr2;
  153. int but_exit;
  154.  
  155.         fsel_input(pathname,filename,&but_exit);/* file selector        */
  156.  
  157.         ptr1=pathname;
  158.         while(*ptr1++)                          /* find end of string   */
  159.                 ;
  160.         while(*ptr1!='\\')                      /* find last \ and      */
  161.                 *ptr1--;                        /* replace the          */
  162.         ptr2=filename;                          /* remainder by the     */
  163.         while(*++ptr1 = *ptr2++)                /* filename to complete */
  164.                 ;                               /* the pathname         */
  165.  
  166.         if (but_exit)
  167.                 {
  168.                 if ((file_handle=Fopen(pathname,2))<0L)
  169.                         form_alert(2,"[3][Cannot open this file][Cancel]");
  170.                 }       
  171.         else
  172.                 file_handle = -1L;
  173. }
  174.  
  175. /************************************************************************/
  176.  
  177. time_out()
  178. {
  179. long lg;
  180.  
  181.         lg=60000L;
  182.         while (lg--)
  183.                 ;
  184. }
  185.  
  186. /************************************************************************/
  187.  
  188. rd_wr()                                 /* read: mode 0, write: mode 1  */
  189. {
  190. char *ptr64;
  191. int i;
  192.  
  193.         if (temp_ptr==buf64)
  194.                 return;
  195.  
  196.         ptr64=buf64;
  197.  
  198.         if (mode)
  199.                 for (i=0;i<64;i++)      /* copy 64 bytes in memory      */
  200.                         *temp_ptr++ = *ptr64++; 
  201.  
  202.         else
  203.                 for (i=0;i<64;i++)      /* copy 64 bytes to work buffer */
  204.                         *ptr64++ = *temp_ptr++;
  205.  
  206. }
  207.  
  208. /************************************************************************/
  209.  
  210. c_peek(mem_ptr)                         /* read protected memory        */
  211. char *mem_ptr;
  212. {
  213.         temp_ptr=mem_ptr;
  214.         mode=0;
  215.         Supexec(rd_wr);
  216. }
  217.  
  218. /************************************************************************/
  219.  
  220. c_poke(mem_ptr)                         /* write protected memory       */
  221. char *mem_ptr;
  222. {
  223.         temp_ptr=mem_ptr;
  224.         mode=1;
  225.         Supexec(rd_wr);
  226. }
  227.  
  228. /************************************************************************/
  229.  
  230. main()
  231. {
  232.         appl_init();
  233.         phys_handle=graf_handle(&d,&d,&d,&d);
  234.         menu_id=menu_register(gl_apid,"  Tiny tool");
  235.         graf_mouse(0,0);                /* arrow form                   */
  236.         wi_handle=NO_WINDOW;
  237.         butdown=1;
  238.  
  239.         multi();
  240. }
  241.  
  242. /************************************************************************/
  243.  
  244. open_vwork()                                    /* open workstation     */
  245. {
  246. int i, rez;
  247.  
  248.         for(i=0;i<10;work_in[i++]=1);      
  249.                 work_in[10]=2;
  250.         handle=phys_handle;
  251.         v_opnvwk(work_in,&handle,work_out);
  252.  
  253.  
  254.         rez=Getrez();
  255.         if (!rez)
  256.                 {
  257.                 form_alert(2,"[3][ |HIGH or MEDIUM resolution only][Cancel]");
  258.                 appl_exit();
  259.                 exit=1;
  260.                 }
  261.  
  262.         h_chr= (rez==2) ? 10:8;         /* high:medium resolution       */
  263.         vst_height(handle,6,&d,&d,&d,&d);
  264. }
  265.  
  266. /************************************************************************/
  267.  
  268. open_window()                                   /* open window          */
  269. {
  270.         wind_get(0,WF_WORKXYWH,&xdesk,&ydesk,&wdesk,&hdesk);
  271.         wi_handle=wind_create(WI_KIND,xdesk+20,ydesk+30,404,19*h_chr);
  272.         wind_set(wi_handle,WF_NAME," TINY TOOL EDITOR ",0,0);
  273.         wind_open(wi_handle,xdesk+20,ydesk+30,404,19*h_chr);
  274. }
  275.  
  276. /************************************************************************/
  277.  
  278. multi()
  279. {
  280. int event, k;
  281.  
  282.         while (1)
  283.                 {
  284.                 event = evnt_multi(MU_MESAG | MU_BUTTON,
  285.                                 1,1,butdown,0,0,0,0,0,0,0,0,0,0,
  286.                                 msgbuff,0,0,&mx,&my,&d,&d,&d,&d);
  287.  
  288.                 wind_update(1);
  289.                 wind_get(wi_handle,WF_TOP,&top_window,&d,&d,&d);
  290.  
  291.                 if (event & MU_MESAG)
  292.  
  293. /*..................................................begin switch........*/
  294. switch (msgbuff[0])
  295. {
  296.         case WM_NEWTOP:case WM_TOPPED:
  297.         if (msgbuff[3] == wi_handle)
  298.                 {
  299.                 wind_set(wi_handle,WF_TOP,0,0,0,0);
  300.                 draw();
  301.                 }
  302.         break;
  303.  
  304.         case AC_CLOSE:
  305.         if ((msgbuff[3] == menu_id)&&(wi_handle != NO_WINDOW))
  306.                 {
  307.                 v_clsvwk(handle);
  308.                 wi_handle = NO_WINDOW;
  309.                 }
  310.         break;
  311.  
  312.         case WM_CLOSED:
  313.         if (msgbuff[3] == wi_handle)
  314.                 {
  315.                 if (open_flag==1)       /* close openned file           */
  316.                         Fclose((int) file_handle);
  317.                 wind_close(wi_handle);
  318.                 wind_delete(wi_handle);
  319.                 v_clsvwk(handle);
  320.                 wi_handle = NO_WINDOW;
  321.                 }
  322.         break;
  323.  
  324.         case WM_MOVED:
  325.         if (msgbuff[3] == wi_handle)
  326.                 {
  327.                 wind_set(wi_handle,WF_CURRXYWH,msgbuff[4]
  328.                         ,msgbuff[5],msgbuff[6],msgbuff[7]);
  329.                 wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  330.                 draw();
  331.                 }
  332.         break;
  333.  
  334.         case AC_OPEN:
  335.         if (msgbuff[4] == menu_id && wi_handle == NO_WINDOW)
  336.                 {
  337.                 open_vwork();
  338.                 if (!exit)
  339.                         {
  340.                         open_window();
  341.                         reset();        /* choice editor screen         */
  342.                         }
  343.                 }
  344.         break;
  345.  
  346. }
  347. /*....................................................end switch........*/
  348.  
  349.                 if ((event & MU_BUTTON)&&(wi_handle == top_window))
  350.                         if (butdown)
  351.                                 wait(clicked());
  352.                         else
  353.                                 butdown=1;
  354.  
  355.                 wind_update(0);
  356.  
  357.         }                                       /* end of while (1)     */
  358.  
  359. }
  360.  
  361. /************************************************************************/
  362.  
  363. draw()
  364. {
  365. int i;
  366. static char box_name[5][6]={"  \001","  \002","RESET","WRITE","PRINT"};
  367. static char ch_name[3][7]={"MEMORY","SECTOR"," FILE"};
  368. static char intr[8][43]={"Parameters in decimal or hexa. (32 or $20)"
  369.                         "drive and side are 0 or 1",
  370.                         "To modifie some byte, click on their hexa",
  371.                         "representation and click WRITE",
  372.                         "RESET to renew, PRINT dump to printer",
  373.                         "\001 and \002 to see above and below",
  374.                         "------------------------------- by A.Birtz",
  375.                         "Click on the Editor of your choice"};
  376.  
  377.         wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  378.         graf_mouse(256,0);              /* hide mouse                   */
  379.  
  380.         wd[0]=xwork;                    /* work area                    */
  381.         wd[1]=ywork;
  382.         wd[2]=xwork+wwork;
  383.         wd[3]=ywork+hwork;
  384.         fill(wd,2,5);                   /*  dark grey diagonal texture  */
  385.  
  386.         ed_scr[0]=xwork+10;             /* editor area                  */
  387.         ed_scr[1]=ywork+h_chr;
  388.         ed_scr[2]=xwork+wwork-10;
  389.         ed_scr[3]=ywork+11*h_chr;
  390.  
  391.         if(intro_lvl)                   /* work screen                  */
  392.  
  393.         {
  394.         mess[0]=ed_scr[0];              /* message area                 */
  395.         mess[1]=ywork+hwork-5*h_chr;
  396.         mess[2]=ed_scr[2];
  397.         mess[3]=mess[1]+(3*h_chr)/2;
  398.  
  399.         for(i=0;i<5;i++)                /* work button                  */
  400.                 {
  401.                 box[i][0]=ed_scr[0]+83*i;
  402.                 box[i][1]=ywork+hwork-(5*h_chr)/2;
  403.                 box[i][2]=box[i][0]+50;
  404.                 box[i][3]=box[i][1]+(3*h_chr)/2;
  405.                 fill(box[i],0,0);       /* white space                  */
  406.                 v_gtext(handle,box[i][0]+6,box[i][1]+h_chr,box_name[i]);
  407.                 }
  408.         }
  409.  
  410.         else                            /* introduction screen          */
  411.  
  412.         {
  413.         fill(ed_scr,0,0);               /*  white space                 */
  414.         for(i=0;i<8;i++)
  415.                 v_gtext(handle,ed_scr[0]+16,ed_scr[1]+h_chr*(i+2),intr[i]);
  416.  
  417.         for (i=0;i<3;i++)
  418.                 {                       /* choice button                */
  419.                 ch[i][0]=xwork+(3*i+1)*wwork/10;
  420.                 ch[i][1]=ywork+3*hwork/4;
  421.                 ch[i][2]=ch[i][0]+2*wwork/10;
  422.                 ch[i][3]=ch[i][1]+3*h_chr/2;
  423.                 fill(ch[i],0,0);        /* white space                  */
  424.                 v_gtext(handle,ch[i][0]+16,ch[i][1]+h_chr,ch_name[i]);
  425.                 }
  426.         }
  427.         
  428.         graf_mouse(257,0);              /* show mouse                   */
  429. }
  430.  
  431. /************************************************************************/
  432.  
  433. fill(rect,style,index)
  434. int rect[], style, index;
  435. {
  436.         graf_mouse(256,0);              /* hide mouse                   */
  437.         vsf_interior(handle,style);     /* fill inside the rect.        */
  438.         vsf_style(handle,index);        /* with index and style param.  */
  439.         v_bar(handle,rect);
  440.         graf_mouse(257,0);              /* show mouse                   */
  441. }
  442.  
  443. /************************************************************************/
  444.  
  445. line(mem_adr,no)
  446. char *mem_adr;
  447. long no;
  448. {
  449. int i, j, n, h_nib, l_nib;
  450. char cc,s[9];
  451.  
  452.         ltohxs(no,s,8);                 /* convert no to hexa. string   */
  453.         i=0;
  454.         while(i<2)                      /* 2 header space               */
  455.                 line_str[i++]=' ';
  456.         while(i<10)                     /* no in hexadecimal            */
  457.                 line_str[i]=s[i++ -2];
  458.         while(i<12)                     /* 2 more space                 */
  459.                 line_str[i++]=' ';
  460.         for (j=0;j<8;j++)               /* 8 byte in hexa and 8 chr     */
  461.                 {
  462.                 cc = *mem_adr++;        /* pick the chr in memory       */
  463.                 n = cc & 0xff;          /* low byte                     */
  464.                 h_nib=n>>4;             /* first hexa digit of byte     */
  465.                 line_str[i++]=h_nib+((h_nib>9) ? 55:48);
  466.                 l_nib = n & 0xF;        /* last hexa digit of byte      */
  467.                 line_str[i++]=l_nib+((l_nib>9) ? 55:48);
  468.                 line_str[i++]=' ';      /* space between 2 byte         */
  469.                                         /* displaying character         */
  470.                 if(n && (dev || (n>31 && n<128)))
  471.                         line_str[j+37]=cc;
  472.                 else                    /* if not printable: dot        */
  473.                         line_str[j+37]='.';
  474.                 }
  475.         line_str[i++]=' ';              /* one more space before 8 chr  */
  476.         for (j=46;j<48;j++)             /* last 2 space                 */
  477.                 line_str[j]=' ';
  478.         line_str[j]='\0';
  479. }
  480.  
  481. /************************************************************************/
  482.  
  483. readline(s,max_len,xpos,ypos)
  484. char *s;
  485. int max_len,xpos,ypos;
  486. {
  487. int i,xy_loc[2];
  488. char cc;
  489.  
  490.         vsin_mode(handle,4,1);
  491.         xy_loc[0]=xpos;
  492.         xy_loc[1]=ypos;
  493.         i=0;
  494.         do {
  495.         vrq_string(handle,1,1,xy_loc,s+i);      /* read char.           */
  496.         cc = *(s+i);
  497.  
  498.         if (cc>47 && cc<58 || cc>64 && cc<71 || cc>96 && cc<103 || cc=='$') 
  499.                                                 /* deci. or hexa. numb. */
  500.                 {
  501.                 v_gtext(handle,xpos,ypos,s);
  502.                 i++;
  503.                 }
  504.  
  505.         if (i && (cc==8 || cc==127))            /* backspace or delete  */
  506.                 {
  507.                 *(s+i)='\0';
  508.                 i--;
  509.                 *(s+i)=' ';
  510.                 v_gtext(handle,xpos,ypos,s);    /* erase...             */
  511.                 *(s+i)='\0';
  512.                 }
  513.         } while (cc && i<max_len);
  514. }
  515.  
  516. /************************************************************************/
  517.  
  518. clicked()
  519. {
  520. int i,r3;
  521.  
  522.         if (intro_lvl)
  523.                 {
  524.                 for(i=0;i<5;i++)        /* if  a clickable box          */
  525.                         if (inside(box[i]))
  526.                                 return(1000+i);
  527.  
  528.  
  529.                 if (my>ed_scr[1]+h_chr && my<ed_scr[3]-h_chr
  530.                         && mx>ed_scr[0]+98 && mx<ed_scr[0]+282)
  531.                         {               /* if byte in the editor screen */
  532.                         r3=(mx-ed_scr[0]-98)/8;
  533.                         if (r3%3==2)
  534.                                 return(-1);
  535.                         return(8*((my-ed_scr[1])/h_chr-1) + r3/3);
  536.                         }
  537.                 }
  538.         else
  539.                 for(i=0;i<3;i++)        /* if choice editor button      */
  540.                         if (inside(ch[i]))
  541.                                 return(2000+i);
  542.  
  543.         return(-1);                     /* bad click                    */
  544. }
  545.  
  546. /************************************************************************/
  547.  
  548. inside(rect)                            /* return 1 if the mouse is     */
  549. int rect[];                             /* inside rect, 0 otherwise     */
  550. {
  551.         if (mx>rect[0] && mx<rect[2] && my>rect[1] && my<rect[3])
  552.                 return(1);
  553.         else
  554.                 return(0);
  555. }
  556.  
  557. /************************************************************************/
  558.  
  559. change(byte_no)
  560. int byte_no;
  561. {
  562. char s[3];
  563.  
  564.         message("Actual value:",0,1);
  565.         ltohxs((long) (buf64[byte_no] & 0xFF),s,2);
  566.         message(s,14,0);
  567.         message("New value:",19,0);
  568.         buf64[byte_no]=i_param(30);
  569.         display(buf64,counter);
  570.         clear_flag=1;
  571. }
  572.  
  573. /************************************************************************/
  574.  
  575. print()
  576. {
  577. char *s, *ptr64;
  578. int i;
  579. long lg;
  580.  
  581.         if (!Cprnos())                  /* check printer status         */
  582.                 {
  583.                 message("Printer not ready, check and retry",0,1);
  584.                 return;
  585.                 }
  586.  
  587.         ptr64=buf64;
  588.         lg=counter;
  589.         dev=0;
  590.  
  591.         Cprnout('\n');                  /* blank line                   */
  592.         Cprnout('\r');
  593.  
  594.         for(i=0;i<8;i++)                /* print no, bytes and char     */
  595.                 {
  596.                 Cprnout('\n');          /* next line                    */
  597.                 Cprnout('\r');
  598.                 line(ptr64,lg);
  599.                 s=line_str;
  600.                 while (*s)
  601.                         Cprnout(*s++);  /* the line...                  */
  602.                 ptr64 += 8L;
  603.                 lg += 8L;
  604.                 }
  605.  
  606.         clear_flag=1;
  607.         dev=2;
  608. }
  609.  
  610. /************************************************************************/
  611.  
  612. wait(clk)
  613. int clk;
  614. {
  615.         if (clk<0)
  616.                 return;
  617.  
  618.         if (intro_lvl)                  /* work screen                  */
  619.                 {
  620.                 if (clear_flag)
  621.                                 {
  622.                                 fill(mess,0,0);
  623.                                 clear_flag=0;
  624.                                 }
  625.  
  626.                 switch(clk) {
  627.                 case 1000:up();break;           /* up arrow button      */
  628.                 case 1001:down();break;         /* down arrow button    */
  629.                 case 1002:reset();break;        /* RESET button         */
  630.                 case 1003:write();break;        /* WRITE button         */
  631.                 case 1004:print();break;        /* PRINT button         */
  632.                 default:break; }
  633.  
  634.                 if (clk<1000)
  635.                         change(clk);
  636.                 }
  637.         else
  638.                 {
  639.  
  640.                 ed_choice=clk-2000;             /* choice screen        */
  641.                 intro_lvl=1;
  642.                 draw();
  643.  
  644.                 switch(ed_choice) {
  645.                 case 0:memory();break;          /* MEMORY button        */
  646.                 case 1:sector();break;          /* SECTOR button        */
  647.                 case 2:file();break;            /* FILE button          */
  648.                 default:break; }
  649.  
  650.                 }
  651. }
  652.  
  653. /************************************************************************/
  654.  
  655. write()
  656. {
  657. long status;
  658.  
  659.         if (ed_choice==0)               /* write byte in memory         */
  660.                 {
  661.                 c_poke(main_ptr);
  662.                 status=0L;
  663.                 }
  664.  
  665.         if (ed_choice==1)               /* write current sector         */
  666.                 {
  667.                 c_poke(main_ptr);
  668.                 status=Flopwr(buf512,0L,drv,sec,trk,side,1);
  669.                 }
  670.  
  671.         if (ed_choice==2)               /* write 64 bytes on file       */
  672.                 {
  673.                 Fseek(main_ptr,(int) file_handle,0);
  674.                 status=Fwrite((int) file_handle,64L,buf64);
  675.                 }
  676.  
  677.         if (status<0L)
  678.                 message("Write error!",0,1);
  679.         else
  680.                 message("Done...",0,1);
  681.  
  682.         clear_flag=1;
  683. }
  684.         
  685. /************************************************************************/
  686.  
  687. down()
  688. {
  689.         main_ptr += 64;
  690.         counter += 64L;
  691.         n_up_down();
  692. }
  693.  
  694. /************************************************************************/
  695.  
  696. up()
  697. {
  698.         main_ptr -= 64;
  699.         counter -= 64L;
  700.         n_up_down();
  701. }
  702.  
  703. /************************************************************************/
  704.  
  705. n_up_down()
  706. {
  707.         if (ed_choice==0)               /* memory editor                */
  708.                 display(main_ptr,counter);
  709.  
  710.         if (ed_choice==1)               /* sector editor                */
  711.                 if (counter<0L || counter>512L)
  712.                         {
  713.                         message("Out of sector",0,1);
  714.                         clear_flag=1;
  715.                         }
  716.                 else
  717.                         display(main_ptr,counter);
  718.  
  719.         if (ed_choice==2)               /* file editor                  */
  720.                 {
  721.                 Fseek(main_ptr,(int) file_handle,0);
  722.                 file_read();
  723.                 display(buf64,counter);
  724.                 }
  725. }
  726.  
  727. /************************************************************************/
  728. reset()
  729. {
  730.         intro_lvl=0;
  731.         draw();
  732. }
  733.  
  734. /************************************************************************/
  735.  
  736. memory()
  737. {
  738.         time_out();
  739.         message("Start address:",0,1);
  740.                                         /* keep starting address        */
  741.         main_ptr=l_param(16);
  742.         counter=main_ptr;
  743.         display(main_ptr,counter);
  744. }
  745.  
  746. /************************************************************************/
  747.  
  748. sector()
  749. {
  750.         message("Drive:",0,1);
  751.         drv=i_param(7);
  752.         message("Side:",11,0);
  753.         side=i_param(17);
  754.         message("Sector:",21,0);
  755.         sec=i_param(29);
  756.         message("Track:",33,0);
  757.         trk=i_param(40);
  758.  
  759.         if (sec_read()<0L)
  760.                 return;                 /* error                        */
  761.         main_ptr=buf512;
  762.         counter=0L;
  763.         display(main_ptr,counter);
  764. }
  765.  
  766. /************************************************************************/
  767.  
  768. sec_read()
  769. {
  770. long status;
  771.  
  772.         status=Floprd(buf512,0L,drv,sec,trk,side,1);
  773.  
  774.         if (status)
  775.                 {
  776.                 message("Read error!",0,1);
  777.                 clear_flag=1;
  778.                 return((int) status);
  779.                 }
  780. }
  781.  
  782. /************************************************************************/
  783.  
  784. file()
  785. {
  786. long status;
  787.  
  788.         if (open_flag==1)
  789.                 {                       /* close openned file           */
  790.                 Fclose((int) file_handle);
  791.                 open_flag=0;
  792.                 }
  793.  
  794.         file_sel();                     /* choice a file                */
  795.  
  796.         draw();
  797.         if (file_handle<0L)
  798.                 return;                 /* error                        */
  799.  
  800.         time_out();
  801.         message("File offset (beginning=0)",0,1);
  802.                                         /* keep file offset             */
  803.         main_ptr=l_param(30);
  804.  
  805.         open_flag=1;
  806.         counter=main_ptr;
  807.         Fseek(counter,(int) file_handle,0);
  808.         file_read();
  809.         display(buf64,counter);
  810. }
  811.  
  812. /************************************************************************/
  813.  
  814. file_read()
  815. {
  816. int i;
  817. long status;
  818.  
  819.         status=Fread((int) file_handle,64L,buf64);
  820.         if (status<0L)                  /* status < 0L mean error       */
  821.                 {
  822.                 message("Read error!",0,1);
  823.                 clear_flag=1;
  824.                 return;
  825.                 }
  826.         if (status<64L)                 /* status > -1L mean # of read  */
  827.                 for (i=(int) status;i<64;i++)
  828.                         buf64[i]='\0';  /* fill tail with zero          */
  829. }
  830.  
  831. /************************************************************************/
  832.  
  833. display(ptr_mem,lg)
  834. long lg;
  835. char *ptr_mem;
  836. {
  837. char *ptr64;
  838. int i;
  839.  
  840.         c_peek(ptr_mem);                /* read in supervisor mode      */
  841.  
  842.         ptr64=buf64;
  843.  
  844.         graf_mouse(256,0);              /* hide mouse                   */
  845.         fill(ed_scr,0,0);               /* blank space                  */
  846.  
  847.         for(i=2;i<10;i++)               /* print no, bytes and char     */
  848.                 {
  849.                 line(ptr64,lg);
  850.                 v_gtext(handle,ed_scr[0]+2,ed_scr[1]+h_chr*i,line_str);
  851.                 ptr64 += 8L;
  852.                 lg += 8L;
  853.                 }
  854.  
  855.         graf_mouse(257,0);              /* show mouse                   */
  856. }
  857.  
  858. /************************************************************************/
  859.  
  860. message(text,chr_1_pos,clear)
  861. char *text;
  862. int chr_1_pos, clear;
  863. {
  864.         if (clear)
  865.                 fill(mess,0,0);         /* white space                  */
  866.         graf_mouse(256,0);              /* hide mouse                   */
  867.         v_gtext(handle,mess[0]+12+8*chr_1_pos,mess[1]+h_chr,text);
  868.                                         /* print message                */
  869.         graf_mouse(257,0);              /* show mouse                   */
  870. }
  871.  
  872.